package com.wondream.myframework.io.file;

import com.google.common.base.Strings;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.io.Resources;

import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

/**
 * 使用Nio的Files
 */
public class NioFilesTest {

    public static final String FILE_NAME = "application.yml";

    public static void main(String[] args) throws Exception {
        URL resourceURL = Resources.getResourceURL(FILE_NAME);
        File resourceAsFile = Resources.getResourceAsFile(FILE_NAME);
        String path = resourceURL.getPath();
        String absolutePath = resourceAsFile.getAbsolutePath();
        printLines(Files.readAllLines(Paths.get(path)));
        printLines(Files.readAllLines(Paths.get(absolutePath)));

    }

    public static void printLines(List<String> content) {
        System.out.println("输出内容为：");
        System.out.println(StringUtils.join(content, System.lineSeparator()));
    }
}
